home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: undoRemoveRootEntry.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:56:03 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "latch.h"
- #include "semaphore.h"
- #include "link.h"
- #include "lsn.h"
- #include "bf.h"
- #include "log.h"
- #include "volume.h"
- #include "logrecs.h"
- #include "undo.h"
- #include "io_logfuncs.h"
- #include "io_extfuncs.h"
- #include "undo_extfuncs.h"
- #include "bf_extfuncs.h"
- #include "util_funcs.h"
- #include "thread_globals.h"
-
-
- void
- undoRemoveRootEntry (
-
- LOGRECORDHDR *recordHeader
- )
- {
-
- register ROOTENTRY *current;
- register ROOTENTRY *end;
- register VOLREC *volRec;
- register GROUPLINK *rootLink;
- ROOTPAGE *rootPage;
- char *oldData;
- int oldDataSize;
- PID pid;
- VOLID volid;
- ROOTENTRYLOGINFO *entryInfo;
-
-
- TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN));
-
- /*
- * get a pointer to the volume id in the record
- */
- volid = recordHeader->actionPid.volid;
- TRPRINT(TR_IO, TR_LEVEL_2, ("volid:%d", volid));
-
- /* get a pointer to information about the entry */
- entryInfo = (ROOTENTRYLOGINFO*) GET_LOG_IMAGE(recordHeader, 0);
- TRPRINT(TR_IO, TR_LEVEL_2, ("name:%s", entryInfo->name));
- TRPRINT(TR_IO, TR_LEVEL_2, ("oldFlags:%d", entryInfo->oldFlags));
-
- /*
- * get a pointer to the old data and its size in the record
- */
- oldData = GET_LOG_IMAGE(recordHeader, 1);
- oldDataSize = GET_LOG_IMAGE_SIZE(recordHeader, 1);
- TRPRINT(TR_IO, TR_LEVEL_2, ("oldData:%s", oldData));
-
- if ((volRec = io_FindVolRec(volid)) == NULL) {
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * construct the pid of the header page
- */
- pid.volid = volid;
- pid.page = ROOTPAGEADDR;
- SM_ASSERT(LEVEL_3, ROOTPAGEADDR == recordHeader->actionPid.page);
-
- /*
- * read in the root page
- */
- if ((rootLink = bf_ReadPage(volRec->bufGroup, &pid, MIN_PAGE2SIZE, BF_SEM)) == NULL) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * get a pointer to the root page
- */
- rootPage = (ROOTPAGE *) rootLink->bufFrame;
-
- /*
- * Initialize the search variables
- */
- current = &(rootPage->entry[0]);
- end = &(rootPage->entry[MAX_ROOT_ENTRIES]);
-
- /*
- * look for a free spot
- */
- while (current < end) {
-
- /*
- * check to see if the slot is free
- */
- if (current->flags != ROOT_FREE) {
-
- /*
- * check to see if the name matches
- */
- if (!strcmp(current->name, (char *)entryInfo->name)) {
-
- /* this was removed, so it should not be here */
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
-
- } else {
-
- /* log the changes */
- if (io_LogSetRootEntry(current->name,
- oldData, 0, /* this is minimum filler for old value */
- oldData, oldDataSize, ROOT_FREE, rootLink->pageHash,
- &(recordHeader->previousLSN) )) {
-
- bf_UnfixPage(rootLink, BF_DEFAULT, FALSE);
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
-
- /* Restore the old data */
- strncpy(current->name, (char*) entryInfo->name, MAX_ROOTNAME_SIZE);
- bcopy(oldData, current->data, oldDataSize);
- current->dataSize = oldDataSize;
- current->flags = ROOT_USED;
-
- /* signal the semaphore and unfix the page */
- signalSemaphore( &(rootLink->pageHash->semaphore) );
- bf_UnfixPage(rootLink, BF_DEFAULT, TRUE);
-
- return;
- }
-
- /* look at the next entry */
- current++;
- }
-
- /*
- * return an error
- */
- TRPRINT(TR_IO, TR_LEVEL_2, ("no space for root name"));
- SM_ERROR(TYPE_FATAL, esmBADROOTNAME);
- }
-